<!--
 * @Author: sxb
 * @Email: sxb@mail.com
 * @Date: 2020-05-21 11:17:00
 * @Descripttion: 
--> 
<template>
  <div class="app-container">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item v-show="userType != 5 & userType != 1" label="企业名称">
        <el-input v-model="formInline.user" placeholder="请输入企业名称"></el-input>
      </el-form-item>
      <el-form-item label="填报月份">
        <el-date-picker v-model="formInline.dateMonth" type="month" placeholder="请选择月份" value-format="yyyy-MM"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">搜 索</el-button>
        <el-button @click="resetForm">清 除</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="companyName" label="企业名单">
      </el-table-column>
      <el-table-column prop="declareMonth" label="填报月份">
      </el-table-column>
      <el-table-column prop="forecastNumber" label="下月预估量">
      </el-table-column>
      <el-table-column prop="adjustmentNumber" label="调整量">
      </el-table-column>
      <el-table-column prop="updateTime" label="填报时间">
        <template slot-scope="scope">                    
          <span v-if="scope.row.status == 0"></span>
          <span v-if="scope.row.status == 1">{{scope.row.updateTime}}</span>              
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="120">
        <template slot-scope="scope">                    
          <span v-if="scope.row.status == 0" style='color:red'>！未填报</span>
          <span v-if="scope.row.status == 1">已完成</span>     
          <span v-if="scope.row.status == 2">已过期</span>               
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
          <!-- <el-button v-if="scope.row.status == 0" type="text" size="small">提醒</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      style="margin-top: 8px;"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page = pageIndex
      :page-size= pageSize
      layout="total, sizes, prev, pager, next, jumper"
      :total= tableTotal
    ></el-pagination>
    <el-dialog title="月度申报" :visible.sync="dialogDetailVisible" width="20%">
      <el-row>
        <el-col :span="8" class="text-align-right">
          <p>企业名称：</p>
        </el-col>
        <el-col :span="12">
          <p>{{detailInfo.companyName}}</p>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8" class="text-align-right">
          <p>填报月份：</p>
        </el-col>
        <el-col :span="12">
          <p>{{detailInfo.declareMonth}}</p>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8" class="text-align-right">
          <p>下月预估量：</p>
        </el-col>
        <el-col :span="12">
          <p>{{detailInfo.forecastNumber}}</p>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8" class="text-align-right">
          <p>本月调整量：</p>
        </el-col>
        <el-col :span="12">
          <p>{{detailInfo.adjustmentNumber}}</p>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8" class="text-align-right">
          <p>填报时间：</p>
        </el-col>
        <el-col :span="12">
          <p>{{detailInfo.createTime}}</p>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>
<script>
  import { apiGetDeclareMonth } from "../../../api/longtermsalesplan/declareMonth";
  import { parseTime } from "@/utils/index"

  export default {
    data() {
      return {
        userInfo: null,
        userType: null,
        dialogDetailVisible: false,
        tableData: [],
        tableTotal: 0,
        pageIndex: 1,
        pageSize: 10,
        formInline: {
          user: '',
          dateMonth: ''
        },
        detailInfo: ''
      }
    },
    created() {
        this.userInfo = this.$store.state.user.user
        this.userType = this.$store.state.user.user.userType
        this.getDeclareMonth()
    },
    methods: {
      getDeclareMonth(){
        let paramObj = { 
          deptExtName: this.formInline.user, 
          declareMonth: this.formInline.dateMonth, 
          page: this.pageIndex,
          size: this.pageSize }
        apiGetDeclareMonth(paramObj)
        .then(res => {
          let dataList = res.content;
          let newDataList = [];
          if (dataList != null && dataList.length > 0) {
            dataList.forEach(element => {
              newDataList.push({ 
                companyName: element.deptExt == null ? '' : element.deptExt.name,
                declareMonth: parseTime(element.createTime,'{y}-{m}'),
                forecastNumber: element.forecastNumber,
                adjustmentNumber: element.adjustmentNumber,
                actualNumber: element.actualNumber,
                createTime: element.createTime,
                //updateTime: parseTime(element.updateTime,'{y}-{m}-{d} {h}:{m}:{s}'),
                updateTime: element.updateTime,
                status: element.status,
                correctNumber: element.correctNumber
              });
            });
          }
          this.tableData = newDataList;
          this.tableTotal = res.totalElements;
        })
        .catch(error => {
          console.log(error);
        });
      },
      onSubmit() {
        this.getDeclareMonth()
      },
      resetForm(){
        this.formInline.user = '';
        this.formInline.dateMonth = '';
      },
      handleClick(row) {
        this.dialogDetailVisible = true;
        this.detailInfo = row;
        console.log('this.detailInfo');
        console.log(this.detailInfo);
      },
      handleSizeChange(val) {
      },
      handleCurrentChange(val) {
      }
    }
  }
</script>
<style scoped>
.text-align-right{
  text-align: right;
}
p {
    display: block;
    margin-block-start: 1em;
    margin-block-end: 1em;
    margin-inline-start: 0px;
    margin-inline-end: 0px;
}
</style>
